package com.gagakuai.test;

import java.util.concurrent.CompletableFuture;
import java.util.function.Function;

/*
 * @program: settement
 * @description:
 * @author: houhong
 * @create: 2022-11-27 13:41
 */
public class MoneyServiceImpl implements MoneyService {
    @Override
    public CompletableFuture<String> addMoney(int money) throws InterruptedException {
        return CompletableFuture.supplyAsync(()->{
            try {
                System.out.println("成功增加"+money);
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "第一步完成";
        }).thenApplyAsync(lastResult -> {
            //这里的入参是上一步的结果
            System.out.println(lastResult);
            return "扣减了" + money;
        });
    }

    @Override
    public CompletableFuture<String> subMoney(int money) throws InterruptedException {
        return CompletableFuture.supplyAsync(()->{
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "成功扣减"+money;
        });
    }
}